package com.ram.controller;

import com.ram.pojo.Room;
import com.ram.pojo.RoomDTO;
import com.ram.pojo.RoomVO;
import com.ram.pojo.PageResult;
import com.ram.pojo.Result;
import com.ram.service.RoomService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/room")
public class RoomController {
    @Autowired
    private RoomService roomService;

    @GetMapping("/list")
    public Result list(@RequestParam Integer buildingId) {
        return Result.success(roomService.list(buildingId));
    }

    @GetMapping("/{id}")
    public Result getById(@PathVariable Integer id) {
        return Result.success(roomService.getById(id));
    }

    @PostMapping
    public Result add(@RequestBody Room room) {
        roomService.add(room);
        return Result.success();
    }

    @PutMapping
    public Result update(@RequestBody Room room) {
        roomService.update(room);
        return Result.success();
    }

    @DeleteMapping("/{id}")
    public Result delete(@PathVariable Integer id) {
        roomService.deleteById(id);
        return Result.success();
    }

    // 分页+条件查询
    @PostMapping("/page")
    public Result pageQuery(@RequestBody RoomDTO dto) {
        PageResult<RoomVO> pageResult = roomService.pageQuery(dto);
        return Result.success(pageResult);
    }
} 